home *** CD-ROM | disk | FTP | other *** search
/ Pro-Cent Games: For Only 1 Cent! / Pro Cent Games.bin / DoubleBreak.exe / scripts / frame_2 / DoAction.as
Encoding:
Text File  |  2003-02-23  |  4.3 KB  |  199 lines

  1. function moveTheBalls()
  2. {
  3.    x = 1;
  4.    while(theNumberOfBalls >= x)
  5.    {
  6.       thisBall = theBallsList["ball" + x];
  7.       if(!thisBall == 0)
  8.       {
  9.          thisBall.moveBall();
  10.       }
  11.       x++;
  12.    }
  13. }
  14. function newBallList(startBallNum)
  15. {
  16.    this["ball" + startBallNum] = new newBall("ball" + startBallNum);
  17. }
  18. function addNewBall()
  19. {
  20.    theNumberOfBalls++;
  21.    theCurBallNum++;
  22.    theBallsList["ball" + theNumberOfBalls] = new newBall("ball" + theNumberOfBalls);
  23. }
  24. function maketargetList(numOfTiles)
  25. {
  26.    i = 0;
  27.    while(i < numOfTiles)
  28.    {
  29.       gTargetList[i] = String("tile" + (i + 1));
  30.       i++;
  31.    }
  32. }
  33. function newBall(instName)
  34. {
  35.    duplicateMovieClip("ball",instName,16384 + theNumberOfBalls);
  36.    this.name = instName;
  37.    this.MovieClip = _root[instName];
  38.    this.MovieClip._x = gBallBaseLoc[0];
  39.    this.MovieClip._y = gBallBaseLoc[1];
  40.    this.deltaX = getRandom(-5,5);
  41.    this.deltaY = -10;
  42.    this.HitNum = 0;
  43. }
  44. function resetGame()
  45. {
  46.    maketargetList(gTileNum);
  47.    resetTiles();
  48. }
  49. function resetTiles()
  50. {
  51.    i = 0;
  52.    while(i < gTileNum)
  53.    {
  54.       var thisTile = gTargetList[i];
  55.       _root[thisTile]._x = _root[thisTile].startX;
  56.       i++;
  57.    }
  58. }
  59. function checkForXtraBall(theBallName)
  60. {
  61.    var xtraBallNum = xtraBallList.length;
  62.    i = 0;
  63.    while(i < xtraBallNum)
  64.    {
  65.       if(theBallName eq xtraBallList[i])
  66.       {
  67.          return 1;
  68.       }
  69.       i++;
  70.    }
  71. }
  72. function getRandom(x, y)
  73. {
  74.    return Math.round(Math.random() * (y - x)) + x;
  75. }
  76. Mouse.hide();
  77. gameOn = 1;
  78. theScore = 0;
  79. gBallBaseLoc = [200,300];
  80. gThePaddle = [_root.paddle,_root.paddle2];
  81. gGameRect = [0,0,400,500];
  82. gHMax = pGameRect[2] - 5;
  83. gTileNum = 35;
  84. gTargetList = [];
  85. maketargetList(gTileNum);
  86. theNumberOfBalls = 1;
  87. theCurBallNum = 1;
  88. theBallsList = new newBallList(theNumberOfBalls);
  89. ballsLeft = 2;
  90. xtraBallList = ["tile16","tile18","tile33"];
  91. _root.resetTiles();
  92. newBall.prototype.moveBall = function()
  93. {
  94.    this.MovieClip._x += this.deltaX;
  95.    this.MovieClip._y += this.deltaY;
  96.    if(this.MovieClip._y < 0)
  97.    {
  98.       this.flipY();
  99.    }
  100.    var theTileNum = gTargetList.length;
  101.    i = 0;
  102.    while(i < theTileNum)
  103.    {
  104.       var thisTile = gTargetList[i];
  105.       if(this.MovieClip.hitTest(_root[thisTile]))
  106.       {
  107.          this.increaseSpeed();
  108.          theScore += 10 * theCurBallNum;
  109.          _root[thisTile]._x += -1000;
  110.          gTargetList.splice(i,1);
  111.          this.flipY();
  112.          if(checkForXtraBall(thisTile))
  113.          {
  114.             addNewBall();
  115.          }
  116.          if(gTargetList.length == 0)
  117.          {
  118.             resetGame();
  119.          }
  120.          break;
  121.       }
  122.       i++;
  123.    }
  124.    thisPad = 0;
  125.    while(thisPad < 2)
  126.    {
  127.       var thePaddle = gThePaddle[thisPad];
  128.       if(this.MovieClip.hitTest(thePaddle) && 0 < this.deltaY)
  129.       {
  130.          this.paddleHit(thePaddle);
  131.       }
  132.       thisPad++;
  133.    }
  134.    if(gGameRect[3] + 20 < this.MovieClip._y)
  135.    {
  136.       theBallsList[this.name] = 0;
  137.       removeMovieClip(this.MovieClip);
  138.       theCurBallNum--;
  139.       if(0 >= theCurBallNum)
  140.       {
  141.          ballsLeft--;
  142.          if(ballsLeft < 0)
  143.          {
  144.             ballsLeft = 0;
  145.             gameOn = 0;
  146.             gotoAndStop(6);
  147.          }
  148.          else
  149.          {
  150.             addNewBall();
  151.          }
  152.       }
  153.    }
  154.    if(this.MovieClip._x < gGameRect[0] || gGameRect[2] < this.MovieClip._x)
  155.    {
  156.       this.flipX();
  157.    }
  158. };
  159. newBall.prototype.serveBall = function()
  160. {
  161.    this.MovieClip._x = gBallBaseLoc[0];
  162.    this.MovieClip._y = gBallBaseLoc[1];
  163.    this.deltaX = getRandom(-5,5);
  164.    this.deltaY = -10;
  165. };
  166. newBall.prototype.flipY = function()
  167. {
  168.    this.deltaY *= -1;
  169. };
  170. newBall.prototype.flipX = function()
  171. {
  172.    this.deltaX *= -1;
  173. };
  174. newBall.prototype.paddleHit = function(thePaddle)
  175. {
  176.    this.deltaX = (this.MovieClip._x - thePaddle._x) / 4;
  177.    this.flipY();
  178.    this.MovieClip._y = Math.min(this.MovieClip._y,thePaddle._y + 10);
  179. };
  180. newBall.prototype.increaseSpeed = function()
  181. {
  182.    if(!(this.deltaY < -18 || 18 < this.deltaY))
  183.    {
  184.       this.hitNum = this.hitNum + 1;
  185.       if(3 < this.hitNum)
  186.       {
  187.          this.hitNum = 0;
  188.          if(0 < this.deltaY)
  189.          {
  190.             this.deltaY = this.deltaY + 1;
  191.          }
  192.          else
  193.          {
  194.             this.deltaY--;
  195.          }
  196.       }
  197.    }
  198. };
  199.